#include<stdio.h>

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	int ret[16] = {0};
	int arr[300][300];
	int i, j;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			scanf("%d", &arr[i][j]);
			ret[arr[i][j]]++;
		}
	}
	for (i = 0; i < 16; i++)
	{
		if(ret[i] == 0) 
			continue;
		else
			printf("%d %d\n", i, ret[i]);
	}
	
	return 0;
}


